<?php

class Request_model extends CI_Model {

	function __construct() {
		parent::__construct();
	}

	//Insert a new request for an offer
	function insert_request($request){
		$sql = "INSERT INTO request (offer_id, fb_id, status, date_created) VALUES (?, ?, ?, NOW())";		
		$result = $this->db->query($sql, array($request['offer_id']. $request['fb_id'], REQUEST_PENDING));

		return $result;
	}
	
	//Retrieve requests based on fb_id
	function get_requests_by_fb_id($fb_id){
		$sql = "SELECT * FROM request WHERE fb_id = ?";
		$query = $this->db->query($sql, $fb_id);
			
		$data = array();
		if($query->num_rows() > 0){
			foreach ($query->result_array() as $row) {
				$data[] = $row;
			}		
		}
		return $data;
	}
	
	//Retrieve requests based on offer_id
	function get_requests_by_offer_id($offer_id){
		$sql = "SELECT * FROM request WHERE offer_id = ?";
		$query = $this->db->query($sql, $fb_id);
			
		$data = array();
		if($query->num_rows() > 0){
			foreach ($query->result_array() as $row) {
				$data[] = $row;
			}		
		}
		return $data;
	}
}
?>